//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Tips.h"
#include "MainForm.h"
#include <Registry.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmTips *frmTips;
//---------------------------------------------------------------------------
__fastcall TfrmTips::TfrmTips(TComponent* Owner)
	: TForm(Owner)
{
	ftips = new TStringList();
	ItemIndex=0;
	if(FileExists("tips.txt"))
	{
		ftips->LoadFromFile("tips.txt");
		lblTips->Caption = ftips->Strings[0];
	}
	else
	{
        ftips->Text = Memo1->Text;
    }

}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::CreateParams(TCreateParams &Params)
{  
   TForm::CreateParams(Params); 
   Params.Style  &=  ~WS_CHILD;
   Params.Style    |=  WS_POPUP;
   Params.WndParent  =  frmmain->Handle;
}
__fastcall TfrmTips::~TfrmTips()
{
    delete ftips;
}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::btnNextClick(TObject *Sender)
{
 if(ItemIndex<ftips->Count-1)
 {
 ItemIndex++;
 }
 else
 {
	 ItemIndex=0;
 }
 lblTips->Caption = ftips->Strings[ItemIndex];
}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;	
}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::btnCloseClick(TObject *Sender)
{
if(frmmain->iShowTips != this->CheckBox1->Checked)
{
	frmmain->iShowTips = this->CheckBox1->Checked;
	SaveReg();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::FormCreate(TObject *Sender)
{
if(frmmain->iShowTips)
{
    this->CheckBox1->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmTips::SaveReg()
{
	TRegistry *Registry = new TRegistry(KEY_ALL_ACCESS);
	try
	{
		Registry->RootKey = HKEY_LOCAL_MACHINE;
		// False because we do not want to create it if it doesn't exist
		if(Registry->OpenKey("Software\\adm\\neteye",true))
		{
			Registry->WriteBool("ShowTips",frmmain->iShowTips);
			Registry->CloseKey();
		}
	}
	__finally
	{
		delete Registry;
	}
}
//---------------------------------------------------------------------------
